package pers.kw.feign.fallback;

import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import pers.kw.entity.TokenInfoDto;
import pers.kw.feign.AuthApiService;
import pers.kw.protocol.R;

@Component
public class AuthServerFallbackFactory implements FallbackFactory<AuthApiService> {

    private static final Logger log = LoggerFactory.getLogger(AuthServerFallbackFactory.class);

    @Override
    public AuthApiService create(Throwable throwable) {
        log.error("AuthServer调用异常:", throwable);
        return new AuthApiService() {
            @Override
            public R<TokenInfoDto> accessToken(String grantType, String scope, String username, String password, String userType) {
                return R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), "AuthServer异常");
            }

            @Override
            public R<TokenInfoDto> refreshToken(String grantType, String scope, String username, String userType, String refresh_token) {
                return R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), "AuthServer异常");
            }
        };
    }
}
